package cn.sxt.yxl.controller.head;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.sxt.common.controller.BaseController;
import cn.sxt.yxl.common.util.PageInfoUtil;
import cn.sxt.yxl.question.pojo.AColumns;
import cn.sxt.yxl.question.pojo.AColumnsEnum;
import cn.sxt.yxl.question.pojo.AItems;
import cn.sxt.yxl.question.service.IAColumnsService;
import cn.sxt.yxl.question.service.IAItemsService;

@Controller
public class controllerYxl extends BaseController{

	@Resource
	private IAColumnsService columnsService;
	@Resource
	private IAItemsService itemsService;

	@RequestMapping("/main")
	public String main(HttpServletRequest request) {

		return "back/main";
	}

	//
//	@RequestMapping("/{url}")
//	public String itemList(HttpServletRequest request,@PathVariable String url) {
//		System.out.println("url-------------------------");
//		Map<String, Object> condMap = new HashMap<String, Object>();
//		condMap.put("url", url);
//		AColumns columns = columnsService.findOne(condMap);
//		request.setAttribute("columns", columns);
//		
//		condMap.clear();
//		condMap.put("status", AColumnsEnum.STATUS_ENABLE.getStatus());
//		condMap.put("columnsId", columns.getId());
//		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
//		List<AItems> itemsList = itemsService.findMany(condMap, pageInfoUtil);
//		System.out.println("url01-------------------------");
//		request.setAttribute("itemsList", itemsList);
//		request.setAttribute("pageInfoUtil", pageInfoUtil);
//		return "back/itemList";
//	}

	@RequestMapping("/header")
	public String header(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", AColumnsEnum.STATUS_ENABLE.getStatus());
		List<AColumns> list = columnsService.findMany(map, null);
		request.setAttribute("columnsList", list);

		System.out.println("header-------------------------");
		return "head/header";
	}
	
	@RequestMapping("/info_{iid}")
	public String info(HttpServletRequest request,@PathVariable int  iid){
		Map<String,Object> condMap = new HashMap<String ,Object>();
		condMap.put("id", iid);
		AItems items = itemsService.findOne(condMap);
		request.setAttribute("items", items);
		return "head/itemsInfo";
	}
	
	@RequestMapping("/ceshi_{iid}")
	public String ceshi(HttpServletRequest request,@PathVariable int iid){
		Map<String,Object> condMap = new HashMap<String ,Object>();
		condMap.put("id", iid);
		AItems items = itemsService.findOne(condMap);
		request.setAttribute("items", items);
		
		return "head/ceshi";
	}
}
